{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "e76463f3",
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests\n",
    "import pandas as pd\n",
    "# time模块主要用于获取当前时间\n",
    "import time \n",
    "# 设置打印DataFrame最大的显示条数\n",
    "pd.set_option('max_rows',500)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "a375164f",
   "metadata": {},
   "outputs": [],
   "source": [
    "headers = {\n",
    "    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36'\n",
    "}\n",
    "\n",
    "url = 'https://c.m.163.com/ug/api/wuhan/app/data/list-total'   # 定义要访问的地址\n",
    "r = requests.get(url, headers=headers)  # 使用requests发起请求"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "0a6a5685",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "200"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.status_code"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "928ca9df",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "str"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(r.text)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "5eb3ff50",
   "metadata": {},
   "outputs": [],
   "source": [
    "import json # 导入json模块\n",
    "# 使用loads方法将json字符串变成json对象（实际上是dict）\n",
    "data_json = json.loads(r.text)\n",
    "# 查看有哪些key\n",
    "data_json.keys()\n",
    "data = data_json['data'] # 取出json中的数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "b9365cc9",
   "metadata": {},
   "outputs": [],
   "source": [
    "data_province = data['areaTree'][2]['children']  # 取出中国各省的实时数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "d3acf478",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "湖北 2021-05-13 00:00:47\n",
      "香港 2021-05-13 09:00:58\n",
      "广东 2021-05-13 09:00:58\n",
      "上海 2021-05-13 08:31:01\n",
      "黑龙江 2021-05-13 00:00:46\n"
     ]
    }
   ],
   "source": [
    "i = 1\n",
    "for province in data_province:\n",
    "    print(province['name'],province['lastUpdateTime'])\n",
    "    if i==5:\n",
    "        break\n",
    "    i= i +1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "ee13838f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>today</th>\n",
       "      <th>total</th>\n",
       "      <th>extData</th>\n",
       "      <th>name</th>\n",
       "      <th>id</th>\n",
       "      <th>lastUpdateTime</th>\n",
       "      <th>children</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>{'confirm': 0, 'suspect': None, 'heal': 0, 'de...</td>\n",
       "      <td>{'confirm': 68158, 'suspect': 0, 'heal': 63640...</td>\n",
       "      <td>{}</td>\n",
       "      <td>湖北</td>\n",
       "      <td>420000</td>\n",
       "      <td>2021-05-13 00:00:47</td>\n",
       "      <td>[{'today': {'confirm': 0, 'suspect': None, 'he...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>{'confirm': 2, 'suspect': None, 'heal': 2, 'de...</td>\n",
       "      <td>{'confirm': 11814, 'suspect': 0, 'heal': 11505...</td>\n",
       "      <td>{}</td>\n",
       "      <td>香港</td>\n",
       "      <td>810000</td>\n",
       "      <td>2021-05-13 09:00:58</td>\n",
       "      <td>[{'today': {'confirm': 2, 'suspect': None, 'he...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>{'confirm': 2, 'suspect': None, 'heal': 5, 'de...</td>\n",
       "      <td>{'confirm': 2383, 'suspect': 0, 'heal': 2321, ...</td>\n",
       "      <td>{}</td>\n",
       "      <td>广东</td>\n",
       "      <td>440000</td>\n",
       "      <td>2021-05-13 09:00:58</td>\n",
       "      <td>[{'today': {'confirm': 2, 'suspect': None, 'he...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>{'confirm': 2, 'suspect': None, 'heal': 5, 'de...</td>\n",
       "      <td>{'confirm': 2025, 'suspect': 0, 'heal': 1960, ...</td>\n",
       "      <td>{}</td>\n",
       "      <td>上海</td>\n",
       "      <td>310000</td>\n",
       "      <td>2021-05-13 08:31:01</td>\n",
       "      <td>[{'today': {'confirm': 2, 'suspect': None, 'he...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>{'confirm': 0, 'suspect': None, 'heal': 0, 'de...</td>\n",
       "      <td>{'confirm': 1610, 'suspect': 0, 'heal': 1597, ...</td>\n",
       "      <td>{}</td>\n",
       "      <td>黑龙江</td>\n",
       "      <td>230000</td>\n",
       "      <td>2021-05-13 00:00:46</td>\n",
       "      <td>[{'today': {'confirm': 0, 'suspect': None, 'he...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                               today  \\\n",
       "0  {'confirm': 0, 'suspect': None, 'heal': 0, 'de...   \n",
       "1  {'confirm': 2, 'suspect': None, 'heal': 2, 'de...   \n",
       "2  {'confirm': 2, 'suspect': None, 'heal': 5, 'de...   \n",
       "3  {'confirm': 2, 'suspect': None, 'heal': 5, 'de...   \n",
       "4  {'confirm': 0, 'suspect': None, 'heal': 0, 'de...   \n",
       "\n",
       "                                               total extData name      id  \\\n",
       "0  {'confirm': 68158, 'suspect': 0, 'heal': 63640...      {}   湖北  420000   \n",
       "1  {'confirm': 11814, 'suspect': 0, 'heal': 11505...      {}   香港  810000   \n",
       "2  {'confirm': 2383, 'suspect': 0, 'heal': 2321, ...      {}   广东  440000   \n",
       "3  {'confirm': 2025, 'suspect': 0, 'heal': 1960, ...      {}   上海  310000   \n",
       "4  {'confirm': 1610, 'suspect': 0, 'heal': 1597, ...      {}  黑龙江  230000   \n",
       "\n",
       "        lastUpdateTime                                           children  \n",
       "0  2021-05-13 00:00:47  [{'today': {'confirm': 0, 'suspect': None, 'he...  \n",
       "1  2021-05-13 09:00:58  [{'today': {'confirm': 2, 'suspect': None, 'he...  \n",
       "2  2021-05-13 09:00:58  [{'today': {'confirm': 2, 'suspect': None, 'he...  \n",
       "3  2021-05-13 08:31:01  [{'today': {'confirm': 2, 'suspect': None, 'he...  \n",
       "4  2021-05-13 00:00:46  [{'today': {'confirm': 0, 'suspect': None, 'he...  "
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.DataFrame(data_province).head() # 直接生成数据效果并不理想"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "dab4c0ff",
   "metadata": {},
   "outputs": [],
   "source": [
    "info = pd.DataFrame(data_province)[['id','name','lastUpdateTime']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "45241e27",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>name</th>\n",
       "      <th>lastUpdateTime</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>420000</td>\n",
       "      <td>湖北</td>\n",
       "      <td>2021-05-13 00:00:47</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>810000</td>\n",
       "      <td>香港</td>\n",
       "      <td>2021-05-13 09:00:58</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>440000</td>\n",
       "      <td>广东</td>\n",
       "      <td>2021-05-13 09:00:58</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>310000</td>\n",
       "      <td>上海</td>\n",
       "      <td>2021-05-13 08:31:01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>230000</td>\n",
       "      <td>黑龙江</td>\n",
       "      <td>2021-05-13 00:00:46</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       id name       lastUpdateTime\n",
       "0  420000   湖北  2021-05-13 00:00:47\n",
       "1  810000   香港  2021-05-13 09:00:58\n",
       "2  440000   广东  2021-05-13 09:00:58\n",
       "3  310000   上海  2021-05-13 08:31:01\n",
       "4  230000  黑龙江  2021-05-13 00:00:46"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "info.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "a9bc4027",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>confirm</th>\n",
       "      <th>suspect</th>\n",
       "      <th>heal</th>\n",
       "      <th>dead</th>\n",
       "      <th>severe</th>\n",
       "      <th>storeConfirm</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>None</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>None</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>-3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2</td>\n",
       "      <td>None</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>-3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   confirm suspect  heal  dead severe  storeConfirm\n",
       "0        0    None     0     0   None             0\n",
       "1        2    None     2     0   None             0\n",
       "2        2    None     5     0   None            -3\n",
       "3        2    None     5     0   None            -3\n",
       "4        0    None     0     0   None             0"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 获取today中的数据\n",
    "today_data = pd.DataFrame([province['today'] for province in data_province ]) \n",
    "today_data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "bd6f9c72",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['confirm', 'suspect', 'heal', 'dead', 'severe', 'storeConfirm'], dtype='object')"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "today_data.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "a2899ca4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>today_confirm</th>\n",
       "      <th>today_suspect</th>\n",
       "      <th>today_heal</th>\n",
       "      <th>today_dead</th>\n",
       "      <th>today_severe</th>\n",
       "      <th>today_storeConfirm</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>None</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>None</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>-3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2</td>\n",
       "      <td>None</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>-3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   today_confirm today_suspect  today_heal  today_dead today_severe  \\\n",
       "0              0          None           0           0         None   \n",
       "1              2          None           2           0         None   \n",
       "2              2          None           5           0         None   \n",
       "3              2          None           5           0         None   \n",
       "4              0          None           0           0         None   \n",
       "\n",
       "   today_storeConfirm  \n",
       "0                   0  \n",
       "1                   0  \n",
       "2                  -3  \n",
       "3                  -3  \n",
       "4                   0  "
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "today_data.columns = ['today_'+i for i in today_data.columns] # 由于today中键名和total键名相同，因此需要修改列名称\n",
    "today_data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "d3ec1833",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>total_confirm</th>\n",
       "      <th>total_suspect</th>\n",
       "      <th>total_heal</th>\n",
       "      <th>total_dead</th>\n",
       "      <th>total_severe</th>\n",
       "      <th>total_input</th>\n",
       "      <th>total_newConfirm</th>\n",
       "      <th>total_newDead</th>\n",
       "      <th>total_newHeal</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>68158</td>\n",
       "      <td>0</td>\n",
       "      <td>63640</td>\n",
       "      <td>4512</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>11814</td>\n",
       "      <td>0</td>\n",
       "      <td>11505</td>\n",
       "      <td>210</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2383</td>\n",
       "      <td>0</td>\n",
       "      <td>2321</td>\n",
       "      <td>8</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2025</td>\n",
       "      <td>0</td>\n",
       "      <td>1960</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1610</td>\n",
       "      <td>0</td>\n",
       "      <td>1597</td>\n",
       "      <td>13</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   total_confirm  total_suspect  total_heal  total_dead  total_severe  \\\n",
       "0          68158              0       63640        4512             0   \n",
       "1          11814              0       11505         210             0   \n",
       "2           2383              0        2321           8             0   \n",
       "3           2025              0        1960           7             0   \n",
       "4           1610              0        1597          13             0   \n",
       "\n",
       "   total_input  total_newConfirm  total_newDead  total_newHeal  \n",
       "0            0               NaN            NaN            NaN  \n",
       "1            0               NaN            NaN            NaN  \n",
       "2            0               NaN            NaN            NaN  \n",
       "3            0               NaN            NaN            NaN  \n",
       "4            0               NaN            NaN            NaN  "
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 获取total中的数据\n",
    "total_data = pd.DataFrame([province['total'] for province in data_province ])\n",
    "total_data.columns = ['total_'+i for i in total_data.columns]\n",
    "total_data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "d8bed127",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>name</th>\n",
       "      <th>lastUpdateTime</th>\n",
       "      <th>today_confirm</th>\n",
       "      <th>today_suspect</th>\n",
       "      <th>today_heal</th>\n",
       "      <th>today_dead</th>\n",
       "      <th>today_severe</th>\n",
       "      <th>today_storeConfirm</th>\n",
       "      <th>total_confirm</th>\n",
       "      <th>total_suspect</th>\n",
       "      <th>total_heal</th>\n",
       "      <th>total_dead</th>\n",
       "      <th>total_severe</th>\n",
       "      <th>total_input</th>\n",
       "      <th>total_newConfirm</th>\n",
       "      <th>total_newDead</th>\n",
       "      <th>total_newHeal</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>420000</td>\n",
       "      <td>湖北</td>\n",
       "      <td>2021-05-13 00:00:47</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "      <td>68158</td>\n",
       "      <td>0</td>\n",
       "      <td>63640</td>\n",
       "      <td>4512</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>810000</td>\n",
       "      <td>香港</td>\n",
       "      <td>2021-05-13 09:00:58</td>\n",
       "      <td>2</td>\n",
       "      <td>None</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "      <td>11814</td>\n",
       "      <td>0</td>\n",
       "      <td>11505</td>\n",
       "      <td>210</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>440000</td>\n",
       "      <td>广东</td>\n",
       "      <td>2021-05-13 09:00:58</td>\n",
       "      <td>2</td>\n",
       "      <td>None</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>-3</td>\n",
       "      <td>2383</td>\n",
       "      <td>0</td>\n",
       "      <td>2321</td>\n",
       "      <td>8</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>310000</td>\n",
       "      <td>上海</td>\n",
       "      <td>2021-05-13 08:31:01</td>\n",
       "      <td>2</td>\n",
       "      <td>None</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>-3</td>\n",
       "      <td>2025</td>\n",
       "      <td>0</td>\n",
       "      <td>1960</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>230000</td>\n",
       "      <td>黑龙江</td>\n",
       "      <td>2021-05-13 00:00:46</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "      <td>1610</td>\n",
       "      <td>0</td>\n",
       "      <td>1597</td>\n",
       "      <td>13</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       id name       lastUpdateTime  today_confirm today_suspect  today_heal  \\\n",
       "0  420000   湖北  2021-05-13 00:00:47              0          None           0   \n",
       "1  810000   香港  2021-05-13 09:00:58              2          None           2   \n",
       "2  440000   广东  2021-05-13 09:00:58              2          None           5   \n",
       "3  310000   上海  2021-05-13 08:31:01              2          None           5   \n",
       "4  230000  黑龙江  2021-05-13 00:00:46              0          None           0   \n",
       "\n",
       "   today_dead today_severe  today_storeConfirm  total_confirm  total_suspect  \\\n",
       "0           0         None                   0          68158              0   \n",
       "1           0         None                   0          11814              0   \n",
       "2           0         None                  -3           2383              0   \n",
       "3           0         None                  -3           2025              0   \n",
       "4           0         None                   0           1610              0   \n",
       "\n",
       "   total_heal  total_dead  total_severe  total_input  total_newConfirm  \\\n",
       "0       63640        4512             0            0               NaN   \n",
       "1       11505         210             0            0               NaN   \n",
       "2        2321           8             0            0               NaN   \n",
       "3        1960           7             0            0               NaN   \n",
       "4        1597          13             0            0               NaN   \n",
       "\n",
       "   total_newDead  total_newHeal  \n",
       "0            NaN            NaN  \n",
       "1            NaN            NaN  \n",
       "2            NaN            NaN  \n",
       "3            NaN            NaN  \n",
       "4            NaN            NaN  "
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.concat([info,today_data,total_data],axis=1).head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "87e9a514",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 将提取数据的方法封装为函数\n",
    "def get_data(data,info_list):\n",
    "    info = pd.DataFrame(data)[info_list] # 主要信息\n",
    "    \n",
    "    today_data = pd.DataFrame([i['today'] for i in data ]) # 生成today的数据\n",
    "    today_data.columns = ['today_'+i for i in today_data.columns] # 修改列名\n",
    "    \n",
    "    total_data = pd.DataFrame([i['total'] for i in data ]) # 生成total的数据\n",
    "    total_data.columns = ['total_'+i for i in total_data.columns] # 修改列名\n",
    "    # info、today和total横向合并最终得到汇总的数据\n",
    "    return pd.concat([info,total_data,today_data],axis=1) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "id": "c443c181",
   "metadata": {},
   "outputs": [],
   "source": [
    "today_province = get_data(data_province,[\"id\",\"name\",\"lastUpdateTime\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "id": "34e200f6",
   "metadata": {},
   "outputs": [],
   "source": [
    "def save_data(data,name): # 定义保存数据方法\n",
    "    file_name = name+'_'+time.strftime('%Y_%m_%d',time.localtime(time.time()))+'.csv'\n",
    "    data.to_csv(file_name,index=None,encoding='utf_8_sig')\n",
    "    print(file_name+' 保存成功！')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "id": "c38f4a2c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "today_province_2021_05_13.csv 保存成功！\n"
     ]
    }
   ],
   "source": [
    "save_data(today_province,'today_province')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "id": "83ea53c0",
   "metadata": {},
   "outputs": [],
   "source": [
    "areaTree = data['areaTree'] # 取出areaTree"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "id": "31c6b9bd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "today_world_2021_05_13.csv 保存成功！\n"
     ]
    }
   ],
   "source": [
    "today_world = get_data(areaTree,['id','lastUpdateTime','name'])\n",
    "save_data(today_world,'today_world')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "id": "28f82cc6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dict_keys(['date', 'today', 'total', 'extData', 'lastUpdateTime'])"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "chinaDayList = data['chinaDayList'] # 取出chinaDayList\n",
    "chinaDayList[0].keys() # 取出第一条数据，并查看其keys"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "id": "62775bdc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "alltime_China_2021_05_13.csv 保存成功！\n"
     ]
    }
   ],
   "source": [
    "alltime_China = get_data(chinaDayList,['date','lastUpdateTime'])\n",
    "save_data(alltime_China,'alltime_China')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "id": "16d8f780",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 构建各省行政代码和省名称对应的字典\n",
    "province_dict = {num:name for num,name in zip(today_province['id'],today_province['name'])}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "id": "13315bc2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'420000': '湖北',\n",
       " '810000': '香港',\n",
       " '440000': '广东',\n",
       " '310000': '上海',\n",
       " '230000': '黑龙江',\n",
       " '330000': '浙江',\n",
       " '130000': '河北',\n",
       " '410000': '河南',\n",
       " '700000': '台湾',\n",
       " '110000': '北京',\n",
       " '430000': '湖南',\n",
       " '510000': '四川',\n",
       " '340000': '安徽',\n",
       " '650000': '新疆',\n",
       " '360000': '江西',\n",
       " '370000': '山东',\n",
       " '320000': '江苏',\n",
       " '500000': '重庆',\n",
       " '350000': '福建',\n",
       " '610000': '陕西',\n",
       " '220000': '吉林',\n",
       " '210000': '辽宁',\n",
       " '120000': '天津',\n",
       " '150000': '内蒙古',\n",
       " '530000': '云南',\n",
       " '450000': '广西',\n",
       " '140000': '山西',\n",
       " '620000': '甘肃',\n",
       " '460000': '海南',\n",
       " '520000': '贵州',\n",
       " '640000': '宁夏',\n",
       " '820000': '澳门',\n",
       " '630000': '青海',\n",
       " '540000': '西藏'}"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "province_dict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "id": "09330f71",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-------------------- 湖北 成功 (480, 16) (480, 16) ,累计耗时: 2 --------------------\n",
      "-------------------- 香港 成功 (480, 16) (960, 16) ,累计耗时: 4 --------------------\n",
      "-------------------- 广东 成功 (478, 16) (1438, 16) ,累计耗时: 5 --------------------\n",
      "-------------------- 上海 成功 (464, 16) (1902, 16) ,累计耗时: 6 --------------------\n",
      "-------------------- 黑龙江 成功 (469, 16) (2371, 16) ,累计耗时: 8 --------------------\n",
      "-------------------- 浙江 成功 (476, 16) (2847, 16) ,累计耗时: 9 --------------------\n",
      "-------------------- 河北 成功 (471, 16) (3318, 16) ,累计耗时: 10 --------------------\n",
      "-------------------- 河南 成功 (478, 16) (3796, 16) ,累计耗时: 12 --------------------\n",
      "-------------------- 台湾 成功 (479, 16) (4275, 16) ,累计耗时: 13 --------------------\n",
      "-------------------- 北京 成功 (472, 16) (4747, 16) ,累计耗时: 14 --------------------\n",
      "-------------------- 湖南 成功 (476, 16) (5223, 16) ,累计耗时: 16 --------------------\n",
      "-------------------- 四川 成功 (473, 16) (5696, 16) ,累计耗时: 17 --------------------\n",
      "-------------------- 安徽 成功 (477, 16) (6173, 16) ,累计耗时: 18 --------------------\n",
      "-------------------- 新疆 成功 (480, 16) (6653, 16) ,累计耗时: 20 --------------------\n",
      "-------------------- 江西 成功 (478, 16) (7131, 16) ,累计耗时: 21 --------------------\n",
      "-------------------- 山东 成功 (472, 16) (7603, 16) ,累计耗时: 22 --------------------\n",
      "-------------------- 江苏 成功 (478, 16) (8081, 16) ,累计耗时: 24 --------------------\n",
      "-------------------- 重庆 成功 (479, 16) (8560, 16) ,累计耗时: 25 --------------------\n",
      "-------------------- 福建 成功 (471, 16) (9031, 16) ,累计耗时: 26 --------------------\n",
      "-------------------- 陕西 成功 (470, 16) (9501, 16) ,累计耗时: 28 --------------------\n",
      "-------------------- 吉林 成功 (473, 16) (9974, 16) ,累计耗时: 29 --------------------\n",
      "-------------------- 辽宁 成功 (467, 16) (10441, 16) ,累计耗时: 30 --------------------\n",
      "-------------------- 天津 成功 (473, 16) (10914, 16) ,累计耗时: 32 --------------------\n",
      "-------------------- 内蒙古 成功 (474, 16) (11388, 16) ,累计耗时: 33 --------------------\n",
      "-------------------- 云南 成功 (471, 16) (11859, 16) ,累计耗时: 34 --------------------\n",
      "-------------------- 广西 成功 (478, 16) (12337, 16) ,累计耗时: 36 --------------------\n",
      "-------------------- 山西 成功 (475, 16) (12812, 16) ,累计耗时: 38 --------------------\n",
      "-------------------- 甘肃 成功 (466, 16) (13278, 16) ,累计耗时: 39 --------------------\n",
      "-------------------- 海南 成功 (476, 16) (13754, 16) ,累计耗时: 40 --------------------\n",
      "-------------------- 贵州 成功 (476, 16) (14230, 16) ,累计耗时: 41 --------------------\n",
      "-------------------- 宁夏 成功 (475, 16) (14705, 16) ,累计耗时: 43 --------------------\n",
      "-------------------- 澳门 成功 (474, 16) (15179, 16) ,累计耗时: 44 --------------------\n",
      "-------------------- 青海 成功 (480, 16) (15659, 16) ,累计耗时: 45 --------------------\n",
      "-------------------- 西藏 成功 (479, 16) (16138, 16) ,累计耗时: 47 --------------------\n"
     ]
    }
   ],
   "source": [
    "start = time.time()\n",
    "for province_id in province_dict: # 遍历各省编号\n",
    "    \n",
    "    try:\n",
    "        # 按照省编号构建每个省的数据地址，获取json数据\n",
    "        url = 'https://c.m.163.com/ug/api/wuhan/app/data/list-by-area-code?areaCode='+province_id\n",
    "        r = requests.get(url, headers=headers)\n",
    "        data_json = json.loads(r.text)\n",
    "        \n",
    "        # 提取各省数据，然后写入各省名称\n",
    "        province_data = get_data(data_json['data']['list'],['date'])\n",
    "        province_data['name'] = province_dict[province_id]\n",
    "        \n",
    "        # 合并数据\n",
    "        # 以数据中第一个省份生成第一个DataFrame，以便后续合并\n",
    "        if province_id == '420000':\n",
    "            alltime_province = province_data\n",
    "        else:\n",
    "            alltime_province = pd.concat([alltime_province,province_data])\n",
    "            \n",
    "        print('-'*20,province_dict[province_id],'成功',\n",
    "              province_data.shape,alltime_province.shape,\n",
    "              ',累计耗时:',round(time.time()-start),'-'*20)\n",
    "        \n",
    "        # 设置延迟等待，防止爬取速度过快，ip被封\n",
    "        time.sleep(1)\n",
    "        \n",
    "    except:\n",
    "        print('-'*20,province_dict[province_id],'wrong','-'*20)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "id": "d55bba25",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "alltime_province_2021_05_13.csv 保存成功！\n"
     ]
    }
   ],
   "source": [
    "# 保存数据\n",
    "save_data(alltime_province,'alltime_province')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "id": "a27926bf",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 构建各国编号和名称对应的字典\n",
    "country_dict = {key:value for key,value in zip(today_world['id'], today_world['name'])}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "id": "19f7c57b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'9577772': '突尼斯',\n",
       " '9507896': '塞尔维亚',\n",
       " '0': '中国',\n",
       " '1': '日本本土',\n",
       " '2': '泰国',\n",
       " '3': '新加坡',\n",
       " '4': '韩国',\n",
       " '5': '澳大利亚',\n",
       " '6': '德国',\n",
       " '7': '美国',\n",
       " '8': '马来西亚',\n",
       " '9': '越南',\n",
       " '89566': '圣巴泰勒米',\n",
       " '821': '肯尼亚',\n",
       " '826': '伊朗',\n",
       " '827': '以色列',\n",
       " '828': '毛利亚尼亚',\n",
       " '829': '黎巴嫩',\n",
       " '833': '克罗地亚',\n",
       " '834': '奥地利',\n",
       " '835': '瑞士',\n",
       " '839': '希腊',\n",
       " '95800': '毛里求斯',\n",
       " '845': '爱沙尼亚',\n",
       " '846': '北马其顿',\n",
       " '850': '白俄罗斯',\n",
       " '851': '立陶宛',\n",
       " '852': '阿塞拜疆',\n",
       " '875097': '美属维尔京群岛',\n",
       " '95826': '蒙古',\n",
       " '872': '乌克兰',\n",
       " '874': '波兰',\n",
       " '879': '波黑',\n",
       " '80902': '蒙特塞拉特',\n",
       " '880': '南非',\n",
       " '95198': '布隆迪',\n",
       " '95215522': '南苏丹',\n",
       " '893': '马耳他',\n",
       " '896': '摩尔多瓦',\n",
       " '897': '保加利亚',\n",
       " '898': '孟加拉',\n",
       " '899': '阿尔巴尼亚',\n",
       " '950000': '巴勒斯坦',\n",
       " '95kml': '科摩罗',\n",
       " '953333': '阿富汗',\n",
       " '95888822': '沙特阿拉伯',\n",
       " '9511123': '新西兰',\n",
       " '95333': '塔吉克斯坦',\n",
       " '83356': '泽西岛',\n",
       " '954467': '叙利亚',\n",
       " '95327': '巴拿马',\n",
       " '95329': '古巴',\n",
       " '9511111': '尼日利亚',\n",
       " '95858585': '摩洛哥',\n",
       " '9500222': '塞内加尔',\n",
       " '95118': '老挝',\n",
       " '95350': '巴哈马',\n",
       " '84226': '马约特岛',\n",
       " '954444': '斯洛文尼亚',\n",
       " '95103': '卢森堡',\n",
       " '95106': '爱尔兰',\n",
       " '95102': '厄瓜多尔',\n",
       " '957777': '捷克',\n",
       " '9522222': '匈牙利',\n",
       " '8101': '法属圭亚那',\n",
       " '8102': '多哥共和国',\n",
       " '8100': '哥斯达黎加',\n",
       " '8105': '文莱',\n",
       " '8103': '法罗群岛',\n",
       " '8104': '马提尼克岛',\n",
       " '95120': '荷兰',\n",
       " '951234567': '巴西',\n",
       " '8115': '洪都拉斯',\n",
       " '95394': '乌拉圭',\n",
       " '95390': '秘鲁',\n",
       " '956666': '智利',\n",
       " '95389': '格陵兰',\n",
       " '95382': '圣巴托洛谬岛',\n",
       " '950101010': '马尔代夫',\n",
       " '95384': '委内瑞拉',\n",
       " '8134': '毛里塔尼亚',\n",
       " '8135': '纳米比亚',\n",
       " '8132': '法属留尼汪岛',\n",
       " '8133': '波多黎各',\n",
       " '95732': '加纳',\n",
       " '8136': '赤道几内亚',\n",
       " '8130': '几内亚',\n",
       " '8131': '卢旺达',\n",
       " '80001': '格林纳达',\n",
       " '8129': '斯威士兰',\n",
       " '8145': '坦桑尼亚',\n",
       " '8146': '贝宁',\n",
       " '8143': '刚果（金）',\n",
       " '8144': '中非共和国',\n",
       " '8147': '利比里亚',\n",
       " '8148': '索马里',\n",
       " '95123456': '塞拉利昂',\n",
       " '95XXXX': '乍得',\n",
       " '8152': '赞比亚',\n",
       " '8151': '巴巴多斯',\n",
       " '95mali': '马里',\n",
       " '958888': '阿根廷',\n",
       " '81113': '法属波利尼西亚',\n",
       " '9584332': '巴林',\n",
       " '8168': '莫桑比克',\n",
       " '95747': '喀麦隆',\n",
       " '8165': '乌干达',\n",
       " '8166': '厄立特里亚',\n",
       " '95983': '刚果（布）',\n",
       " '8162': '津巴布韦',\n",
       " '956475': '丹麦',\n",
       " '81344': '阿鲁巴',\n",
       " '95776': '斐济',\n",
       " '8172': '伯利兹',\n",
       " '8173': '缅甸',\n",
       " '9568067': '塞浦路斯',\n",
       " '81134': '关岛',\n",
       " '888779': '科索沃',\n",
       " '95860612': '圣皮埃尔岛和密克隆岛',\n",
       " '95251456': '吉尔吉斯斯坦',\n",
       " '8197': '博茨瓦纳',\n",
       " '95309': '尼日尔',\n",
       " '95305': '苏里南',\n",
       " '95306': '佛得角',\n",
       " '95786': '萨尔瓦多',\n",
       " '95303': '圭亚那',\n",
       " '95787': '尼加拉瓜',\n",
       " '95783': '冈比亚',\n",
       " '9523416782': '东帝汶',\n",
       " '950777': '巴基斯坦',\n",
       " '9577890': '埃及',\n",
       " '9577665': '科威特',\n",
       " '95903': '斯洛伐克',\n",
       " '95904': '直布罗陀',\n",
       " '959333': '摩纳哥',\n",
       " '9509765': '巴拉圭',\n",
       " '856671': '荷属安的列斯',\n",
       " '95711': '多米尼克',\n",
       " '95703': '乌兹别克斯坦',\n",
       " '95293': '黑山',\n",
       " '95294': '危地马拉',\n",
       " '95290': '加蓬',\n",
       " '95291': '苏丹',\n",
       " '87435': '利比亚',\n",
       " '95287': '圣马丁岛',\n",
       " '95046': '土耳其',\n",
       " '95047': '巴布亚新几内亚',\n",
       " '95000011': '多米尼加',\n",
       " '95076': '约旦',\n",
       " '9532556': '亚美尼亚',\n",
       " '811192': '圣基茨和尼维斯',\n",
       " '89665': '瓜德罗普',\n",
       " '94367': '安提瓜和巴布达',\n",
       " '95215': '玻利维亚',\n",
       " '95693': '哥伦比亚',\n",
       " '879903': '圣文森特和格林纳丁斯',\n",
       " '84326': '圣卢西亚',\n",
       " '10': '法国',\n",
       " '11': '阿联酋',\n",
       " '12': '加拿大',\n",
       " '13': '印度',\n",
       " '14': '英国',\n",
       " '15': '意大利',\n",
       " '16': '俄罗斯',\n",
       " '17': '菲律宾',\n",
       " '18': '芬兰',\n",
       " '19': '尼泊尔',\n",
       " '95682': '葡萄牙',\n",
       " '95200': '也门',\n",
       " '954356': '塞舌尔',\n",
       " '20': '西班牙',\n",
       " '21': '斯里兰卡',\n",
       " '9509': '阿尔及利亚',\n",
       " '22': '柬埔寨',\n",
       " '95239': '海地',\n",
       " '23': '瑞典',\n",
       " '95237': '特里尼达和多巴哥',\n",
       " '95jibuti': '吉布提',\n",
       " '9512314': '圣多美与普林西比',\n",
       " '953487': '布基纳法索',\n",
       " '954332': '比利时',\n",
       " '9534324': '伊拉克',\n",
       " '95000111': '马拉维',\n",
       " '95010': '冰岛',\n",
       " '95jnybs': '几内亚比绍',\n",
       " '953333666': '拉脱维亚',\n",
       " '9512111': '不丹',\n",
       " '957873': '挪威',\n",
       " '9524546': '印度尼西亚',\n",
       " '956789': '安哥拉',\n",
       " '87656': '开曼群岛',\n",
       " '95844': '埃塞俄比亚',\n",
       " '95879': '梵蒂冈',\n",
       " '95632': '科特迪瓦',\n",
       " '95634': '卡塔尔',\n",
       " '95411': '莱索托',\n",
       " '950611': '格鲁吉亚',\n",
       " '96745': '墨西哥',\n",
       " '95891': '圣马力诺',\n",
       " '95400': '哈萨克斯坦',\n",
       " '95643': '安道尔',\n",
       " '95886': '牙买加',\n",
       " '82333': '格恩西岛',\n",
       " '95677': '罗马尼亚',\n",
       " '95436': '阿曼',\n",
       " '95672': '列支敦士登',\n",
       " '9547021': '马达加斯加'}"
      ]
     },
     "execution_count": 75,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "country_dict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "id": "491f727c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-------------------- 突尼斯 成功 (419, 15) (419, 15) ,累计耗时: 1 --------------------\n",
      "-------------------- 塞尔维亚 成功 (424, 15) (843, 15) ,累计耗时: 2 --------------------\n",
      "-------------------- 中国 成功 (461, 15) (1304, 15) ,累计耗时: 3 --------------------\n",
      "-------------------- 日本本土 成功 (438, 15) (1742, 15) ,累计耗时: 5 --------------------\n",
      "-------------------- 泰国 成功 (435, 15) (2177, 15) ,累计耗时: 6 --------------------\n",
      "-------------------- 新加坡 成功 (452, 15) (2629, 15) ,累计耗时: 7 --------------------\n",
      "-------------------- 韩国 成功 (475, 15) (3104, 15) ,累计耗时: 9 --------------------\n",
      "-------------------- 澳大利亚 成功 (434, 15) (3538, 15) ,累计耗时: 10 --------------------\n",
      "-------------------- 德国 成功 (441, 15) (3979, 15) ,累计耗时: 12 --------------------\n",
      "-------------------- 美国 成功 (446, 15) (4425, 15) ,累计耗时: 13 --------------------\n",
      "-------------------- 马来西亚 成功 (438, 15) (4863, 15) ,累计耗时: 14 --------------------\n",
      "-------------------- 越南 成功 (409, 15) (5272, 15) ,累计耗时: 16 --------------------\n",
      "-------------------- 圣巴泰勒米 成功 (30, 15) (5302, 15) ,累计耗时: 17 --------------------\n",
      "-------------------- 肯尼亚 成功 (413, 15) (5715, 15) ,累计耗时: 18 --------------------\n",
      "-------------------- 伊朗 成功 (446, 15) (6161, 15) ,累计耗时: 20 --------------------\n",
      "-------------------- 以色列 成功 (438, 15) (6599, 15) ,累计耗时: 21 --------------------\n",
      "-------------------- 毛利亚尼亚 成功 (12, 15) (6611, 15) ,累计耗时: 22 --------------------\n",
      "-------------------- 黎巴嫩 成功 (421, 15) (7032, 15) ,累计耗时: 24 --------------------\n",
      "-------------------- 克罗地亚 成功 (422, 15) (7454, 15) ,累计耗时: 25 --------------------\n",
      "-------------------- 奥地利 成功 (432, 15) (7886, 15) ,累计耗时: 26 --------------------\n",
      "-------------------- 瑞士 成功 (438, 15) (8324, 15) ,累计耗时: 28 --------------------\n",
      "-------------------- 希腊 成功 (427, 15) (8751, 15) ,累计耗时: 29 --------------------\n",
      "-------------------- 毛里求斯 成功 (399, 15) (9150, 15) ,累计耗时: 30 --------------------\n",
      "-------------------- 爱沙尼亚 成功 (421, 15) (9571, 15) ,累计耗时: 32 --------------------\n",
      "-------------------- 北马其顿 成功 (411, 15) (9982, 15) ,累计耗时: 33 --------------------\n",
      "-------------------- 白俄罗斯 成功 (416, 15) (10398, 15) ,累计耗时: 34 --------------------\n",
      "-------------------- 立陶宛 成功 (418, 15) (10816, 15) ,累计耗时: 36 --------------------\n",
      "-------------------- 阿塞拜疆 成功 (417, 15) (11233, 15) ,累计耗时: 37 --------------------\n",
      "-------------------- 美属维尔京群岛 成功 (30, 15) (11263, 15) ,累计耗时: 38 --------------------\n",
      "-------------------- 蒙古 成功 (61, 15) (11324, 15) ,累计耗时: 40 --------------------\n",
      "-------------------- 乌克兰 成功 (421, 15) (11745, 15) ,累计耗时: 41 --------------------\n",
      "-------------------- 波兰 成功 (426, 15) (12171, 15) ,累计耗时: 43 --------------------\n",
      "-------------------- 波黑 成功 (413, 15) (12584, 15) ,累计耗时: 44 --------------------\n",
      "-------------------- 蒙特塞拉特 成功 (34, 15) (12618, 15) ,累计耗时: 46 --------------------\n",
      "-------------------- 南非 成功 (427, 15) (13045, 15) ,累计耗时: 47 --------------------\n",
      "-------------------- 布隆迪 成功 (40, 15) (13085, 15) ,累计耗时: 48 --------------------\n",
      "-------------------- 南苏丹 成功 (48, 15) (13133, 15) ,累计耗时: 49 --------------------\n",
      "-------------------- 马耳他 成功 (398, 15) (13531, 15) ,累计耗时: 51 --------------------\n",
      "-------------------- 摩尔多瓦 成功 (415, 15) (13946, 15) ,累计耗时: 52 --------------------\n",
      "-------------------- 保加利亚 成功 (419, 15) (14365, 15) ,累计耗时: 54 --------------------\n",
      "-------------------- 孟加拉 成功 (409, 15) (14774, 15) ,累计耗时: 55 --------------------\n",
      "-------------------- 阿尔巴尼亚 成功 (88, 15) (14862, 15) ,累计耗时: 56 --------------------\n",
      "-------------------- 巴勒斯坦 成功 (409, 15) (15271, 15) ,累计耗时: 58 --------------------\n",
      "-------------------- 科摩罗 成功 (34, 15) (15305, 15) ,累计耗时: 59 --------------------\n",
      "-------------------- 阿富汗 成功 (417, 15) (15722, 15) ,累计耗时: 60 --------------------\n",
      "-------------------- 沙特阿拉伯 成功 (429, 15) (16151, 15) ,累计耗时: 62 --------------------\n",
      "-------------------- 新西兰 成功 (422, 15) (16573, 15) ,累计耗时: 63 --------------------\n",
      "-------------------- 塔吉克斯坦 成功 (367, 15) (16940, 15) ,累计耗时: 65 --------------------\n",
      "-------------------- 泽西岛 成功 (30, 15) (16970, 15) ,累计耗时: 66 --------------------\n",
      "-------------------- 叙利亚 成功 (50, 15) (17020, 15) ,累计耗时: 67 --------------------\n",
      "-------------------- 巴拿马 成功 (412, 15) (17432, 15) ,累计耗时: 69 --------------------\n",
      "-------------------- 古巴 成功 (400, 15) (17832, 15) ,累计耗时: 70 --------------------\n",
      "-------------------- 尼日利亚 成功 (419, 15) (18251, 15) ,累计耗时: 72 --------------------\n",
      "-------------------- 摩洛哥 成功 (426, 15) (18677, 15) ,累计耗时: 73 --------------------\n",
      "-------------------- 塞内加尔 成功 (422, 15) (19099, 15) ,累计耗时: 75 --------------------\n",
      "-------------------- 老挝 成功 (44, 15) (19143, 15) ,累计耗时: 76 --------------------\n",
      "-------------------- 巴哈马 成功 (375, 15) (19518, 15) ,累计耗时: 77 --------------------\n",
      "-------------------- 马约特岛 成功 (40, 15) (19558, 15) ,累计耗时: 79 --------------------\n",
      "-------------------- 斯洛文尼亚 成功 (415, 15) (19973, 15) ,累计耗时: 80 --------------------\n",
      "-------------------- 卢森堡 成功 (420, 15) (20393, 15) ,累计耗时: 82 --------------------\n",
      "-------------------- 爱尔兰 成功 (429, 15) (20822, 15) ,累计耗时: 83 --------------------\n",
      "-------------------- 厄瓜多尔 成功 (416, 15) (21238, 15) ,累计耗时: 84 --------------------\n",
      "-------------------- 捷克 成功 (430, 15) (21668, 15) ,累计耗时: 86 --------------------\n",
      "-------------------- 匈牙利 成功 (428, 15) (22096, 15) ,累计耗时: 87 --------------------\n",
      "-------------------- 法属圭亚那 成功 (48, 15) (22144, 15) ,累计耗时: 89 --------------------\n",
      "-------------------- 多哥共和国 成功 (68, 15) (22212, 15) ,累计耗时: 90 --------------------\n",
      "-------------------- 哥斯达黎加 成功 (404, 15) (22616, 15) ,累计耗时: 92 --------------------\n",
      "-------------------- 文莱 成功 (393, 15) (23009, 15) ,累计耗时: 93 --------------------\n",
      "-------------------- 法罗群岛 成功 (47, 15) (23056, 15) ,累计耗时: 94 --------------------\n",
      "-------------------- 马提尼克岛 成功 (370, 15) (23426, 15) ,累计耗时: 96 --------------------\n",
      "-------------------- 荷兰 成功 (439, 15) (23865, 15) ,累计耗时: 97 --------------------\n",
      "-------------------- 巴西 成功 (432, 15) (24297, 15) ,累计耗时: 99 --------------------\n",
      "-------------------- 洪都拉斯 成功 (396, 15) (24693, 15) ,累计耗时: 101 --------------------\n",
      "-------------------- 乌拉圭 成功 (409, 15) (25102, 15) ,累计耗时: 102 --------------------\n",
      "-------------------- 秘鲁 成功 (424, 15) (25526, 15) ,累计耗时: 103 --------------------\n",
      "-------------------- 智利 成功 (431, 15) (25957, 15) ,累计耗时: 105 --------------------\n",
      "-------------------- 格陵兰 成功 (37, 15) (25994, 15) ,累计耗时: 106 --------------------\n",
      "-------------------- 圣巴托洛谬岛 成功 (30, 15) (26024, 15) ,累计耗时: 107 --------------------\n",
      "-------------------- 马尔代夫 成功 (396, 15) (26420, 15) ,累计耗时: 109 --------------------\n",
      "-------------------- 委内瑞拉 成功 (393, 15) (26813, 15) ,累计耗时: 110 --------------------\n",
      "-------------------- 毛里塔尼亚 成功 (381, 15) (27194, 15) ,累计耗时: 112 --------------------\n",
      "-------------------- 纳米比亚 成功 (44, 15) (27238, 15) ,累计耗时: 113 --------------------\n",
      "-------------------- 法属留尼汪岛 成功 (41, 15) (27279, 15) ,累计耗时: 114 --------------------\n",
      "-------------------- 波多黎各 成功 (47, 15) (27326, 15) ,累计耗时: 116 --------------------\n",
      "-------------------- 加纳 成功 (401, 15) (27727, 15) ,累计耗时: 117 --------------------\n",
      "-------------------- 赤道几内亚 成功 (385, 15) (28112, 15) ,累计耗时: 118 --------------------\n",
      "-------------------- 几内亚 成功 (406, 15) (28518, 15) ,累计耗时: 120 --------------------\n",
      "-------------------- 卢旺达 成功 (406, 15) (28924, 15) ,累计耗时: 121 --------------------\n",
      "-------------------- 格林纳达 成功 (39, 15) (28963, 15) ,累计耗时: 123 --------------------\n",
      "-------------------- 斯威士兰 成功 (386, 15) (29349, 15) ,累计耗时: 125 --------------------\n",
      "-------------------- 坦桑尼亚 成功 (388, 15) (29737, 15) ,累计耗时: 126 --------------------\n",
      "-------------------- 贝宁 成功 (382, 15) (30119, 15) ,累计耗时: 127 --------------------\n",
      "-------------------- 刚果（金） 成功 (412, 15) (30531, 15) ,累计耗时: 129 --------------------\n",
      "-------------------- 中非共和国 成功 (381, 15) (30912, 15) ,累计耗时: 131 --------------------\n",
      "-------------------- 利比里亚 成功 (383, 15) (31295, 15) ,累计耗时: 134 --------------------\n",
      "-------------------- 索马里 成功 (390, 15) (31685, 15) ,累计耗时: 135 --------------------\n",
      "-------------------- 塞拉利昂 成功 (385, 15) (32070, 15) ,累计耗时: 136 --------------------\n",
      "-------------------- 乍得 成功 (380, 15) (32450, 15) ,累计耗时: 138 --------------------\n",
      "-------------------- 赞比亚 成功 (399, 15) (32849, 15) ,累计耗时: 140 --------------------\n",
      "-------------------- 巴巴多斯 成功 (52, 15) (32901, 15) ,累计耗时: 141 --------------------\n",
      "-------------------- 马里 成功 (401, 15) (33302, 15) ,累计耗时: 143 --------------------\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-------------------- 阿根廷 成功 (425, 15) (33727, 15) ,累计耗时: 145 --------------------\n",
      "-------------------- 法属波利尼西亚 成功 (36, 15) (33763, 15) ,累计耗时: 146 --------------------\n",
      "-------------------- 巴林 成功 (430, 15) (34193, 15) ,累计耗时: 148 --------------------\n",
      "-------------------- 莫桑比克 成功 (392, 15) (34585, 15) ,累计耗时: 149 --------------------\n",
      "-------------------- 喀麦隆 成功 (406, 15) (34991, 15) ,累计耗时: 151 --------------------\n",
      "-------------------- 乌干达 成功 (403, 15) (35394, 15) ,累计耗时: 152 --------------------\n",
      "-------------------- 厄立特里亚 成功 (50, 15) (35444, 15) ,累计耗时: 154 --------------------\n",
      "-------------------- 刚果（布） 成功 (387, 15) (35831, 15) ,累计耗时: 155 --------------------\n",
      "-------------------- 津巴布韦 成功 (391, 15) (36222, 15) ,累计耗时: 157 --------------------\n",
      "-------------------- 丹麦 成功 (435, 15) (36657, 15) ,累计耗时: 158 --------------------\n",
      "-------------------- 阿鲁巴 成功 (34, 15) (36691, 15) ,累计耗时: 159 --------------------\n",
      "-------------------- 斐济 成功 (370, 15) (37061, 15) ,累计耗时: 161 --------------------\n",
      "-------------------- 伯利兹 成功 (370, 15) (37431, 15) ,累计耗时: 162 --------------------\n",
      "-------------------- 缅甸 成功 (396, 15) (37827, 15) ,累计耗时: 164 --------------------\n",
      "-------------------- 塞浦路斯 成功 (416, 15) (38243, 15) ,累计耗时: 166 --------------------\n",
      "-------------------- 关岛 成功 (33, 15) (38276, 15) ,累计耗时: 167 --------------------\n",
      "-------------------- 科索沃 成功 (34, 15) (38310, 15) ,累计耗时: 168 --------------------\n",
      "-------------------- 圣皮埃尔岛和密克隆岛 成功 (21, 15) (38331, 15) ,累计耗时: 170 --------------------\n",
      "-------------------- 吉尔吉斯斯坦 成功 (402, 15) (38733, 15) ,累计耗时: 171 --------------------\n",
      "-------------------- 博茨瓦纳 成功 (38, 15) (38771, 15) ,累计耗时: 173 --------------------\n",
      "-------------------- 尼日尔 成功 (403, 15) (39174, 15) ,累计耗时: 174 --------------------\n",
      "-------------------- 苏里南 成功 (372, 15) (39546, 15) ,累计耗时: 176 --------------------\n",
      "-------------------- 佛得角 成功 (384, 15) (39930, 15) ,累计耗时: 177 --------------------\n",
      "-------------------- 萨尔瓦多 成功 (384, 15) (40314, 15) ,累计耗时: 179 --------------------\n",
      "-------------------- 圭亚那 成功 (60, 15) (40374, 15) ,累计耗时: 180 --------------------\n",
      "-------------------- 尼加拉瓜 成功 (374, 15) (40748, 15) ,累计耗时: 181 --------------------\n",
      "-------------------- 冈比亚 成功 (41, 15) (40789, 15) ,累计耗时: 183 --------------------\n",
      "-------------------- 东帝汶 成功 (38, 15) (40827, 15) ,累计耗时: 184 --------------------\n",
      "-------------------- 巴基斯坦 成功 (431, 15) (41258, 15) ,累计耗时: 185 --------------------\n",
      "-------------------- 埃及 成功 (429, 15) (41687, 15) ,累计耗时: 187 --------------------\n",
      "-------------------- 科威特 成功 (428, 15) (42115, 15) ,累计耗时: 189 --------------------\n",
      "-------------------- 斯洛伐克 成功 (415, 15) (42530, 15) ,累计耗时: 190 --------------------\n",
      "-------------------- 直布罗陀 成功 (39, 15) (42569, 15) ,累计耗时: 191 --------------------\n",
      "-------------------- 摩纳哥 成功 (69, 15) (42638, 15) ,累计耗时: 193 --------------------\n",
      "-------------------- 巴拉圭 成功 (399, 15) (43037, 15) ,累计耗时: 195 --------------------\n",
      "-------------------- 荷属安的列斯 成功 (27, 15) (43064, 15) ,累计耗时: 196 --------------------\n",
      "-------------------- 多米尼克 成功 (38, 15) (43102, 15) ,累计耗时: 197 --------------------\n",
      "-------------------- 乌兹别克斯坦 成功 (415, 15) (43517, 15) ,累计耗时: 199 --------------------\n",
      "-------------------- 黑山 成功 (398, 15) (43915, 15) ,累计耗时: 200 --------------------\n",
      "-------------------- 危地马拉 成功 (391, 15) (44306, 15) ,累计耗时: 202 --------------------\n",
      "-------------------- 加蓬 成功 (402, 15) (44708, 15) ,累计耗时: 203 --------------------\n",
      "-------------------- 苏丹 成功 (397, 15) (45105, 15) ,累计耗时: 205 --------------------\n",
      "-------------------- 利比亚 成功 (386, 15) (45491, 15) ,累计耗时: 206 --------------------\n",
      "-------------------- 圣马丁岛 成功 (36, 15) (45527, 15) ,累计耗时: 207 --------------------\n",
      "-------------------- 土耳其 成功 (426, 15) (45953, 15) ,累计耗时: 209 --------------------\n",
      "-------------------- 巴布亚新几内亚 成功 (36, 15) (45989, 15) ,累计耗时: 210 --------------------\n",
      "-------------------- 多米尼加 成功 (402, 15) (46391, 15) ,累计耗时: 212 --------------------\n",
      "-------------------- 约旦 成功 (414, 15) (46805, 15) ,累计耗时: 213 --------------------\n",
      "-------------------- 亚美尼亚 成功 (420, 15) (47225, 15) ,累计耗时: 215 --------------------\n",
      "-------------------- 圣基茨和尼维斯 成功 (39, 15) (47264, 15) ,累计耗时: 216 --------------------\n",
      "-------------------- 瓜德罗普 成功 (40, 15) (47304, 15) ,累计耗时: 217 --------------------\n",
      "-------------------- 安提瓜和巴布达 成功 (367, 15) (47671, 15) ,累计耗时: 219 --------------------\n",
      "-------------------- 玻利维亚 成功 (396, 15) (48067, 15) ,累计耗时: 220 --------------------\n",
      "-------------------- 哥伦比亚 成功 (419, 15) (48486, 15) ,累计耗时: 222 --------------------\n",
      "-------------------- 圣文森特和格林纳丁斯 成功 (37, 15) (48523, 15) ,累计耗时: 223 --------------------\n",
      "-------------------- 圣卢西亚 成功 (37, 15) (48560, 15) ,累计耗时: 224 --------------------\n",
      "-------------------- 法国 成功 (442, 15) (49002, 15) ,累计耗时: 225 --------------------\n",
      "-------------------- 阿联酋 成功 (429, 15) (49431, 15) ,累计耗时: 227 --------------------\n",
      "-------------------- 加拿大 成功 (440, 15) (49871, 15) ,累计耗时: 228 --------------------\n",
      "-------------------- 印度 成功 (436, 15) (50307, 15) ,累计耗时: 229 --------------------\n",
      "-------------------- 英国 成功 (442, 15) (50749, 15) ,累计耗时: 231 --------------------\n",
      "-------------------- 意大利 成功 (464, 15) (51213, 15) ,累计耗时: 232 --------------------\n",
      "-------------------- 俄罗斯 成功 (434, 15) (51647, 15) ,累计耗时: 233 --------------------\n",
      "-------------------- 菲律宾 成功 (430, 15) (52077, 15) ,累计耗时: 235 --------------------\n",
      "-------------------- 芬兰 成功 (434, 15) (52511, 15) ,累计耗时: 236 --------------------\n",
      "-------------------- 尼泊尔 成功 (386, 15) (52897, 15) ,累计耗时: 238 --------------------\n",
      "-------------------- 葡萄牙 成功 (425, 15) (53322, 15) ,累计耗时: 239 --------------------\n",
      "-------------------- 也门 成功 (370, 15) (53692, 15) ,累计耗时: 240 --------------------\n",
      "-------------------- 塞舌尔 成功 (41, 15) (53733, 15) ,累计耗时: 242 --------------------\n",
      "-------------------- 西班牙 成功 (443, 15) (54176, 15) ,累计耗时: 243 --------------------\n",
      "-------------------- 斯里兰卡 成功 (418, 15) (54594, 15) ,累计耗时: 244 --------------------\n",
      "-------------------- 阿尔及利亚 成功 (422, 15) (55016, 15) ,累计耗时: 246 --------------------\n",
      "-------------------- 柬埔寨 成功 (386, 15) (55402, 15) ,累计耗时: 247 --------------------\n",
      "-------------------- 海地 成功 (380, 15) (55782, 15) ,累计耗时: 248 --------------------\n",
      "-------------------- 瑞典 成功 (435, 15) (56217, 15) ,累计耗时: 250 --------------------\n",
      "-------------------- 特里尼达和多巴哥 成功 (45, 15) (56262, 15) ,累计耗时: 251 --------------------\n",
      "-------------------- 吉布提 成功 (397, 15) (56659, 15) ,累计耗时: 252 --------------------\n",
      "-------------------- 圣多美与普林西比 成功 (36, 15) (56695, 15) ,累计耗时: 254 --------------------\n",
      "-------------------- 布基纳法索 成功 (413, 15) (57108, 15) ,累计耗时: 255 --------------------\n",
      "-------------------- 比利时 成功 (436, 15) (57544, 15) ,累计耗时: 257 --------------------\n",
      "-------------------- 伊拉克 成功 (437, 15) (57981, 15) ,累计耗时: 258 --------------------\n",
      "-------------------- 马拉维 成功 (378, 15) (58359, 15) ,累计耗时: 259 --------------------\n",
      "-------------------- 冰岛 成功 (423, 15) (58782, 15) ,累计耗时: 261 --------------------\n",
      "-------------------- 几内亚比绍 成功 (384, 15) (59166, 15) ,累计耗时: 262 --------------------\n",
      "-------------------- 拉脱维亚 成功 (421, 15) (59587, 15) ,累计耗时: 263 --------------------\n",
      "-------------------- 不丹 成功 (43, 15) (59630, 15) ,累计耗时: 265 --------------------\n",
      "-------------------- 挪威 成功 (436, 15) (60066, 15) ,累计耗时: 266 --------------------\n",
      "-------------------- 印度尼西亚 成功 (427, 15) (60493, 15) ,累计耗时: 267 --------------------\n",
      "-------------------- 安哥拉 成功 (382, 15) (60875, 15) ,累计耗时: 269 --------------------\n",
      "-------------------- 开曼群岛 成功 (37, 15) (60912, 15) ,累计耗时: 270 --------------------\n",
      "-------------------- 埃塞俄比亚 成功 (401, 15) (61313, 15) ,累计耗时: 272 --------------------\n",
      "-------------------- 梵蒂冈 成功 (42, 15) (61355, 15) ,累计耗时: 273 --------------------\n",
      "-------------------- 科特迪瓦 成功 (414, 15) (61769, 15) ,累计耗时: 274 --------------------\n",
      "-------------------- 卡塔尔 成功 (429, 15) (62198, 15) ,累计耗时: 276 --------------------\n",
      "-------------------- 莱索托 成功 (26, 15) (62224, 15) ,累计耗时: 277 --------------------\n",
      "-------------------- 格鲁吉亚 成功 (421, 15) (62645, 15) ,累计耗时: 278 --------------------\n",
      "-------------------- 墨西哥 成功 (426, 15) (63071, 15) ,累计耗时: 280 --------------------\n",
      "-------------------- 圣马力诺 成功 (394, 15) (63465, 15) ,累计耗时: 281 --------------------\n",
      "-------------------- 哈萨克斯坦 成功 (419, 15) (63884, 15) ,累计耗时: 283 --------------------\n",
      "-------------------- 安道尔 成功 (404, 15) (64288, 15) ,累计耗时: 284 --------------------\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-------------------- 牙买加 成功 (388, 15) (64676, 15) ,累计耗时: 286 --------------------\n",
      "-------------------- 格恩西岛 成功 (29, 15) (64705, 15) ,累计耗时: 287 --------------------\n",
      "-------------------- 罗马尼亚 成功 (428, 15) (65133, 15) ,累计耗时: 288 --------------------\n",
      "-------------------- 阿曼 成功 (429, 15) (65562, 15) ,累计耗时: 290 --------------------\n",
      "-------------------- 列支敦士登 成功 (48, 15) (65610, 15) ,累计耗时: 291 --------------------\n",
      "-------------------- 马达加斯加 成功 (392, 15) (66002, 15) ,累计耗时: 292 --------------------\n",
      "alltime_world_2021_05_13.csv 保存成功！\n"
     ]
    }
   ],
   "source": [
    "start = time.time()\n",
    "for country_id in country_dict: # 遍历每个国家的编号\n",
    "    \n",
    "    try:\n",
    "        # 按照编号访问每个国家的数据地址，并获取json数据\n",
    "        url = 'https://c.m.163.com/ug/api/wuhan/app/data/list-by-area-code?areaCode='+country_id\n",
    "        r = requests.get(url, headers=headers)\n",
    "        json_data = json.loads(r.text)\n",
    "        \n",
    "        # 生成每个国家的数据\n",
    "        country_data = get_data(json_data['data']['list'],['date'])\n",
    "        country_data['name'] = country_dict[country_id]\n",
    "\n",
    "        # 数据叠加\n",
    "        if country_id == '9577772':\n",
    "            alltime_world = country_data\n",
    "        else:\n",
    "            alltime_world = pd.concat([alltime_world,country_data])\n",
    "            \n",
    "        print('-'*20,country_dict[country_id],'成功',country_data.shape,alltime_world.shape,\n",
    "              ',累计耗时:',round(time.time()-start),'-'*20)\n",
    "        \n",
    "        time.sleep(1)\n",
    "\n",
    "    except:\n",
    "        print('-'*20,country_dict[country_id],'wrong','-'*20)\n",
    "        \n",
    "# 保存数据\n",
    "save_data(alltime_world,'alltime_world')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5970003b",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
